package com.project.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.ShowGoodsBean;
import com.project.service.IBiaoShuService;
import com.project.service.IGoodsService;
import com.project.service.impl.ShowGoodsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("showGoods")
@Api(tags = "上架商品控制层")

public class ShowGoodsController {
    @Autowired
    private IBiaoShuService biaoShuService;
    @Autowired
    private ShowGoodsServiceImpl showGoodsService;
    @Autowired
    private IGoodsService goodsService;
    @ApiOperation(value = "请求上架")
    @PostMapping("add")
    public String add(Integer goodsId, double salePrice, String picturePath, Integer esId, String text){//上架
        showGoodsService.add(goodsId, salePrice, picturePath, esId, text);
        return "ok";
    }

    @ApiOperation(value = "审核上架")
    @PutMapping("updateStatus/{showGoodsId}/{newStatus}")
    public String updateStatus(@PathVariable("showGoodsId") Integer showGoodsId,
                               @PathVariable("newStatus") String newStatus){
        showGoodsService.updateStatus(showGoodsId, newStatus);
        if (newStatus.equals("已上架")){
            goodsService.updateStatusToShow(showGoodsId);
            return "ok";
        }else {
            goodsService.updateStatusToShow(showGoodsId);
            return "no";
        }
    }

    @ApiOperation(value = "查看详情")
    @GetMapping("findById")
    public ShowGoodsBean findById(Integer showGoodsId){
        return showGoodsService.findById(showGoodsId);
    }
    @ApiOperation(value = "动态条件分页查询")
    @GetMapping("cutFindByItem")
    public Page<ShowGoodsBean> cutFindByItem(Integer pageNum,String status){
        return showGoodsService.cutFindByItem(pageNum, status);
    }}
